<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是Git中查看提交历史记录的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV01-Git-04-Git本地仓库-03-提交历史">
<meta property="og:url" content="https://sumumm.github.io/post/f7668e71.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是Git中查看提交历史记录的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622172904295.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622173043768.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622173508354.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622173911174.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622174320608.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622174535805.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622175441377.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622175619629.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622181340614.png">
<meta property="article:published_time" content="2023-07-02T07:14:20.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.069Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="Git">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622172904295.png">


<link rel="canonical" href="https://sumumm.github.io/post/f7668e71.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/f7668e71.html","path":"post/f7668e71.html","title":"LV01-Git-04-Git本地仓库-03-提交历史"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV01-Git-04-Git本地仓库-03-提交历史 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E8%8E%B7%E5%8F%96%E4%B8%80%E4%B8%AA%E4%BB%93%E5%BA%93"><span class="nav-text">一、获取一个仓库</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81git-log"><span class="nav-text">二、git log</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%91%BD%E4%BB%A4%E8%AF%B4%E6%98%8E"><span class="nav-text">1. 命令说明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%8F%AF%E9%80%89%E9%80%89%E9%A1%B9"><span class="nav-text">2. 可选选项</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="nav-text">3. 使用实例</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81git-log-p"><span class="nav-text">三、git log -p</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%91%BD%E4%BB%A4%E8%AF%B4%E6%98%8E-1"><span class="nav-text">1. 命令说明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="nav-text">2. 使用实例</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81git-log-%E2%80%93stat"><span class="nav-text">四、git log –stat</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%91%BD%E4%BB%A4%E8%AF%B4%E6%98%8E-2"><span class="nav-text">1. 命令说明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B-1"><span class="nav-text">2. 使用实例</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%94%E3%80%81git-log-%E2%80%93pretty"><span class="nav-text">五、git log –pretty</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%91%BD%E4%BB%A4%E8%AF%B4%E6%98%8E-3"><span class="nav-text">1. 命令说明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-oneline"><span class="nav-text">2. oneline</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-format"><span class="nav-text">3. format</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E4%B8%80%E8%88%AC%E6%A0%BC%E5%BC%8F"><span class="nav-text">3.1 一般格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E5%B8%B8%E7%94%A8%E9%80%89%E9%A1%B9"><span class="nav-text">3.2 常用选项</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E8%87%AA%E5%AE%9A%E4%B9%89%E9%A2%9C%E8%89%B2%E5%AE%9E%E4%BE%8B"><span class="nav-text">3.3 自定义颜色实例</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%85%AD%E3%80%81git-log-%E2%80%93graph"><span class="nav-text">六、git log –graph</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%B8%80%E8%88%AC%E7%94%A8%E6%B3%95"><span class="nav-text">1. 一般用法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B-2"><span class="nav-text">2. 使用实例</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%83%E3%80%81%E9%99%90%E5%88%B6git-log%E8%BE%93%E5%87%BA"><span class="nav-text">七、限制git log输出</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E8%BF%87%E6%BB%A4%E6%8C%87%E5%AE%9A%E7%9A%84%E6%8F%90%E4%BA%A4%E8%AE%B0%E5%BD%95"><span class="nav-text">1. 过滤指定的提交记录</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%B8%B8%E7%94%A8%E7%9A%84%E9%99%90%E5%88%B6%E9%80%89%E9%A1%B9"><span class="nav-text">2. 常用的限制选项</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B-1"><span class="nav-text">3. 使用实例</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%85%AB%E3%80%81%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95"><span class="nav-text">八、自定义提交历史记录</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%AE%9A%E5%88%B6-git-log"><span class="nav-text">1. 定制 git log </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AAgit-log%E5%91%BD%E4%BB%A4"><span class="nav-text">2. 自定义一个git log命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E4%B8%80%EF%BC%9A%E4%BF%AE%E6%94%B9-gitconfig-%E6%96%87%E4%BB%B6"><span class="nav-text">2.1 自定义方法一：修改 ~&#x2F;.gitconfig 文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E4%BA%8C%EF%BC%9A%E5%91%BD%E4%BB%A4%E8%A1%8C%E8%BE%93%E5%85%A5"><span class="nav-text">2.2 自定义方法二：命令行输入</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E8%BF%90%E8%A1%8C%E8%87%AA%E5%AE%9A%E4%B9%89%E5%91%BD%E4%BB%A4"><span class="nav-text">3. 运行自定义命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%AE%9E%E7%8E%B0%E6%95%88%E6%9E%9C"><span class="nav-text">4. 实现效果</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/f7668e71.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV01-Git-04-Git本地仓库-03-提交历史 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV01-Git-04-Git本地仓库-03-提交历史
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-07-02 15:14:20" itemprop="dateCreated datePublished" datetime="2023-07-02T15:14:20+08:00">2023-07-02</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/" itemprop="url" rel="index"><span itemprop="name">开发工具</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/" itemprop="url" rel="index"><span itemprop="name">03版本控制</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>4.5k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>16 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是Git中查看提交历史记录的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向  </td><td align="center">参考原文</td></tr>    <tr><td align="left">Git 官网</td><td align="left"><a href="https://git-scm.com/" target="_blank">https://git-scm.com/ <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Git 官方文档</td><td align="left"><a href="https://git-scm.com/doc" target="_blank">https://git-scm.com/doc <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Pro Git Book</td><td align="left"><a href="https://git-scm.com/book/zh/v2" target="_blank">https://git-scm.com/book/zh/v2 <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Git 快速使用指南</td><td align="left"><a href="https://training.github.com/downloads/zh_CN/github-git-cheat-sheet/" target="_blank">https://training.github.com/downloads/zh_CN/github-git-cheat-sheet/ <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Visual Git Cheat Sheet</td><td align="left"><a href="https://ndpsoftware.com/git-cheatsheet.html#loc=index" target="_blank">https://ndpsoftware.com/git-cheatsheet.html#loc=index <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">---</td>        <td align="left">--- <a href="" target="_blank">  <i class="fa fa-external-link-alt"></i></a></td>      </tr></table>
              </div>
            </details>

<p>【说明】本节笔记的相关操作在Windows下进行，因为VS Code有个Git的插件，可以很直观的演示一些东西。由于Git安装后自带一个Git-Bash终端，所以就不用Win下的命令行啦，就用的这个终端，因为它里边的命令与Linux很类似，而windows中的命令行有些命令与linux并不相同，为了统一，还是用用Git自带的终端啦。另外VS Code是可以选择使用的终端的，我直接将VS Code使用的终端改成了git-bash，这样更方便一些。</p>
<h1 id="一、获取一个仓库"><a href="#一、获取一个仓库" class="headerlink" title="一、获取一个仓库"></a><font size=3>一、获取一个仓库</font></h1><p>在 Pro Git Book 这本书中，有一个项目仓库作为提交记录查看的示例项目，我们将这个仓库clone下来：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone https://github.com/schacon/simplegit-progit</span><br></pre></td></tr></table></figure>

<p>然后我们便会得到一个仓库：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622172904295.png" alt="image-20230622172904295" style="zoom:50%;" />

<h1 id="二、git-log"><a href="#二、git-log" class="headerlink" title="二、git log"></a><font size=3>二、git log</font></h1><h2 id="1-命令说明"><a href="#1-命令说明" class="headerlink" title="1. 命令说明"></a><font size=3>1. 命令说明</font></h2><p>这个就直接输入就好了：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log [可选选项]</span><br></pre></td></tr></table></figure>

<h2 id="2-可选选项"><a href="#2-可选选项" class="headerlink" title="2. 可选选项"></a><font size=3>2. 可选选项</font></h2><p><a target="_blank" rel="noopener" href="https://git-scm.com/book/zh/v2/ch00/log_options"><code>git log</code> 的常用选项</a> 列出了我们目前涉及到的和没涉及到的选项，以及它们是如何影响 log 命令的输出的：</p>
<table>
<thead>
<tr>
<th align="left">选项</th>
<th align="left">说明</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>-p</code></td>
<td align="left">按补丁格式显示每个提交引入的差异。</td>
</tr>
<tr>
<td align="left"><code>--stat</code></td>
<td align="left">显示每次提交的文件修改统计信息。</td>
</tr>
<tr>
<td align="left"><code>--shortstat</code></td>
<td align="left">只显示 –stat 中最后的行数修改添加移除统计。</td>
</tr>
<tr>
<td align="left"><code>--name-only</code></td>
<td align="left">仅在提交信息后显示已修改的文件清单。</td>
</tr>
<tr>
<td align="left"><code>--name-status</code></td>
<td align="left">显示新增、修改、删除的文件清单。</td>
</tr>
<tr>
<td align="left"><code>--abbrev-commit</code></td>
<td align="left">仅显示 SHA-1 校验和所有 40 个字符中的前几个字符。</td>
</tr>
<tr>
<td align="left"><code>--relative-date</code></td>
<td align="left">使用较短的相对时间而不是完整格式显示日期（比如“2 weeks ago”）。</td>
</tr>
<tr>
<td align="left"><code>--graph</code></td>
<td align="left">在日志旁以 ASCII 图形显示分支与合并历史。</td>
</tr>
<tr>
<td align="left"><code>--pretty</code></td>
<td align="left">使用其他格式显示历史提交信息。可用的选项包括 oneline、short、full、fuller 和 format（用来定义自己的格式）。</td>
</tr>
<tr>
<td align="left"><code>--oneline</code></td>
<td align="left"><code>--pretty=oneline --abbrev-commit</code> 合用的简写。</td>
</tr>
</tbody></table>
<h2 id="3-使用实例"><a href="#3-使用实例" class="headerlink" title="3. 使用实例"></a><font size=3>3. 使用实例</font></h2><p>当我们在此项目中运行 <code>git log</code> 命令时，可以看到下面的输出：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622173043768.png" alt="image-20230622173043768" style="zoom:67%;" />

<p>不传入任何参数的默认情况下，<code>git log</code> 会按时间先后顺序列出所有的提交，最近的更新排在最上面。 正如所看到的，这个命令会列出每个提交的 SHA-1 校验和、作者的名字和电子邮件地址、提交时间以及提交说明。SHA-1 校验和也叫hash值，其实就代表了可以这一次的提交，每一次提交都会有这样一个独一无二的hash值。</p>
<h1 id="三、git-log-p"><a href="#三、git-log-p" class="headerlink" title="三、git log -p"></a><font size=3>三、git log -p</font></h1><h2 id="1-命令说明-1"><a href="#1-命令说明-1" class="headerlink" title="1. 命令说明"></a><font size=3>1. 命令说明</font></h2><p>一个比较有用的选项是 <code>-p</code> 或 <code>--patch</code> ，它会显示每次提交所引入的差异（按 <strong>补丁</strong> 的格式输出）。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log -p [-n]</span><br></pre></td></tr></table></figure>

<p>-n是可选的，其中 n 可以限制显示的日志条目数量，可以是任何整数，表示仅显示最近的 <code>n</code> 条提交。例如使用 <code>-2</code> 选项可以只显示最近的两次提交。该选项除了显示基本信息之外，还附带了每次提交的变化。 当进行代码审查，或者快速浏览某个搭档的提交所带来的变化的时候，这个参数就非常有用了。</p>
<h2 id="2-使用实例"><a href="#2-使用实例" class="headerlink" title="2. 使用实例"></a><font size=3>2. 使用实例</font></h2><p>我们显示一下最近一次提交记录：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log -p -1</span><br></pre></td></tr></table></figure>

<p>然后我们会看到如下信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622173508354.png" alt="image-20230622173508354" style="zoom:67%;" />



<h1 id="四、git-log-–stat"><a href="#四、git-log-–stat" class="headerlink" title="四、git log –stat"></a><font size=3>四、git log –stat</font></h1><h2 id="1-命令说明-2"><a href="#1-命令说明-2" class="headerlink" title="1. 命令说明"></a><font size=3>1. 命令说明</font></h2><p>我们也可以为 <code>git log</code> 附带一系列的总结性选项。 比如要是我们想看到每次提交的简略统计信息，可以使用 <code>--stat</code> 选项：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log --stat</span><br></pre></td></tr></table></figure>

<h2 id="2-使用实例-1"><a href="#2-使用实例-1" class="headerlink" title="2. 使用实例"></a><font size=3>2. 使用实例</font></h2><p>我们在仓库中敲以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log --stat</span><br></pre></td></tr></table></figure>

<p>然后我们会得到以下信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622173911174.png" alt="image-20230622173911174" style="zoom:67%;" />

<p>正如所看到的，<code>--stat</code> 选项在每次提交的下面列出所有被修改过的文件、有多少文件被修改了以及被修改过的文件的哪些行被移除或是添加了。 在每次提交的最后还有一个总结。</p>
<h1 id="五、git-log-–pretty"><a href="#五、git-log-–pretty" class="headerlink" title="五、git log –pretty"></a><font size=3>五、git log –pretty</font></h1><h2 id="1-命令说明-3"><a href="#1-命令说明-3" class="headerlink" title="1. 命令说明"></a><font size=3>1. 命令说明</font></h2><p>另一个非常有用的选项是 <code>--pretty</code>。 这个选项可以使用不同于默认格式的方式展示提交历史。 这个选项有一些内建的子选项供我们使用。 比如 <code>oneline</code> 会将每个提交放在一行显示，在浏览大量的提交时非常有用。 另外还有 <code>short</code>，<code>full</code> 和 <code>fuller</code> 选项，它们展示信息的格式基本一致，但是详尽程度不一，一般的格式如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">coption</span><br></pre></td></tr></table></figure>

<h2 id="2-oneline"><a href="#2-oneline" class="headerlink" title="2. oneline"></a><font size=3>2. oneline</font></h2><p>我们来看一下option为oneline的时候，显示的提交记录的样式：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git log --pretty=oneline</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">也可以写成这样</span></span><br><span class="line">git log --oneline  # 把每一个提交信息压缩为一行</span><br></pre></td></tr></table></figure>

<p>然后我们会看到以下输出信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622174320608.png" alt="image-20230622174320608" style="zoom:67%;" />

<h2 id="3-format"><a href="#3-format" class="headerlink" title="3. format"></a><font size=3>3. format</font></h2><h3 id="3-1-一般格式"><a href="#3-1-一般格式" class="headerlink" title="3.1 一般格式"></a><font size=3>3.1 一般格式</font></h3><p>这个参数可以定制记录的显示格式。 这样的输出对后期提取分析格外有用——因为我们知道输出的格式不会随着 Git 的更新而发生改变：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log --pretty=format:&quot;%h - %an, %ar : %s&quot;</span><br></pre></td></tr></table></figure>

<p>然后我们会看到如下输出信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622174535805.png" alt="image-20230622174535805" style="zoom:67%;" />

<h3 id="3-2-常用选项"><a href="#3-2-常用选项" class="headerlink" title="3.2 常用选项"></a><font size=3>3.2 常用选项</font></h3><p><a target="_blank" rel="noopener" href="https://git-scm.com/book/zh/v2/ch00/pretty_format"><code>git log --pretty=format</code> 常用的选项</a> 列出了 <code>format</code> 接受的常用格式占位符的写法及其代表的意义。</p>
<table style="font-size: 13.5px;">
    <tr><td align="center">选项   </td><td align="center"> 说明</td></tr>
<tr><td align="center">%H   </td><td align="left">提交对象（commit）的完整哈希字串</td></tr>
<tr><td align="center">%h   </td><td align="left">提交对象的简短哈希字串</td></tr>
<tr><td align="center">%T   </td><td align="left">树对象（tree）的完整哈希字串</td></tr>
<tr><td align="center">%t   </td><td align="left">树对象的简短哈希字串</td></tr>
<tr><td align="center">%P   </td><td align="left">父对象（parent）的完整哈希字串</td></tr>
<tr><td align="center">%p   </td><td align="left">父对象的简短哈希字串</td></tr>
<tr><td align="center">%an  </td><td align="left">作者（author）的名字</td></tr>
<tr><td align="center">%ae  </td><td align="left">作者的电子邮件地址</td></tr>
<tr><td align="center">%ad  </td><td align="left">作者修订日期（可以用 -date= 选项定制格式）</td></tr>
<tr><td align="center">%ar  </td><td align="left">作者修订日期，按多久以前的方式显示</td></tr>
<tr><td align="center">%cn  </td><td align="left">提交者(committer)的名字</td></tr>
<tr><td align="center">%ce  </td><td align="left">提交者的电子邮件地址</td></tr>
<tr><td align="center">%cd  </td><td align="left">提交日期( --date = 制定的格式)</td></tr>
<tr><td align="center">%cr  </td><td align="left">提交日期，按多久以前的方式显示(1 day ago)</td></tr>
<tr><td align="center">%s   </td><td align="left">提交说明</td></tr>
<tr><td align="center">%d   </td><td align="left">ref 名称</td></tr>
<tr><td align="center">%n   </td><td align="left">换行</td></tr>
</table>
【说明】

<p>（1）在选项前边加上 %C(color) 则可以分别指定输出内容的颜色， color 可选的值有 reset（默认的灰色），normal, black, red, green, yellow, blue, magenta, cyan, white 。另外说明一点就是 color 最好就是可以**带上圆括号 () **，这样既清晰，也不会出错。</p>
<p>（2）作者  和  提交者 之间究竟有何差别， 其实作者指的是实际作出修改的人，提交者指的是最后将此工作成果提交到仓库的人。 所以，当我们为某个项目发布补丁，然后某个核心成员将我们的补丁并入项目时，我们就是作者，而那个核心成员就是提交者。</p>
<h3 id="3-3-自定义颜色实例"><a href="#3-3-自定义颜色实例" class="headerlink" title="3.3 自定义颜色实例"></a><font size=3>3.3 自定义颜色实例</font></h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log --pretty=format:&quot;%Cgreen%an %Cred%h %Cblue%s&quot;      # 以不同颜色显示提交者名字、提交说明和简短的哈希字符串</span><br></pre></td></tr></table></figure>

<p>效果如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622175441377.png" alt="image-20230622175441377" style="zoom:50%;" />

<h1 id="六、git-log-–graph"><a href="#六、git-log-–graph" class="headerlink" title="六、git log –graph"></a><font size=3>六、git log –graph</font></h1><h2 id="1-一般用法"><a href="#1-一般用法" class="headerlink" title="1. 一般用法"></a><font size=3>1. 一般用法</font></h2><p>这个 <code>log</code> 选项 <code>--graph</code> 一般与 <code>oneline</code> 或 <code>format</code> 或者<code>--decorate</code>结合使用。 这个选项添加了一些 ASCII 字符串来形象地展示我们的分支、合并历史，一般用法如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git log --graph --oneline --decorate   # 绘制一幅表示分支结构提交历史的ASCII图 </span><br><span class="line">git log --pretty=format:&quot;%h %s&quot; --graph</span><br></pre></td></tr></table></figure>

<h2 id="2-使用实例-2"><a href="#2-使用实例-2" class="headerlink" title="2. 使用实例"></a><font size=3>2. 使用实例</font></h2><p>我们可以使用上边的命令来查看仓库提交历史的ASCII图：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log --graph --oneline --decorate</span><br></pre></td></tr></table></figure>

<p>但是这个示例仓库提交不够多，也没有分支合并之类的，效果如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622175619629.png" alt="image-20230622175619629" style="zoom:67%;" />

<p>我看手册上是提供了另一个仓库的ASCII图，这里写一下作为参考吧：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git <span class="built_in">log</span> --pretty=format:<span class="string">&quot;%h %s&quot;</span> --graph</span></span><br><span class="line">* 2d3acf9 ignore errors from SIGCHLD on trap</span><br><span class="line">*  5e3ee11 Merge branch &#x27;master&#x27; of git://github.com/dustin/grit</span><br><span class="line">|\</span><br><span class="line">| * 420eac9 Added a method for getting the current branch.</span><br><span class="line">* | 30e367c timeout code and tests</span><br><span class="line">* | 5a09431 add timeout protection to grit</span><br><span class="line">* | e1193f8 support for heads with slashes in them</span><br><span class="line">|/</span><br><span class="line">* d6016bc require time for xmlschema</span><br><span class="line">*  11d191e Merge branch &#x27;defunkt&#x27; into local</span><br></pre></td></tr></table></figure>

<h1 id="七、限制git-log输出"><a href="#七、限制git-log输出" class="headerlink" title="七、限制git log输出"></a><font size=3>七、限制git log输出</font></h1><h2 id="1-过滤指定的提交记录"><a href="#1-过滤指定的提交记录" class="headerlink" title="1. 过滤指定的提交记录"></a><font size=3>1. 过滤指定的提交记录</font></h2><p>除了定制输出格式的选项之外，<code>git log</code> 还有许多非常实用的限制输出长度的选项，也就是只输出一部分的提交。 我们可以使用类似 <code>git log -p -&lt;n&gt;</code> 的选项，其中的 <code>n</code> 可以是任何整数，表示仅显示最近的 <code>n</code> 条提交。 不过实践中这个选项不是很常用，因为 Git 默认会将所有的输出传送到分页程序中，所以我们一次只会看到一页的内容。</p>
<p>但是，类似 <code>--since</code> 和 <code>--until</code> 这种按照时间作限制的选项很有用。 例如，下面的命令会列出最近两周的所有提交：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log --since=2.weeks</span><br></pre></td></tr></table></figure>

<p>该命令可用的格式十分丰富——可以是类似 <code>&quot;2008-01-15&quot;</code> 的具体的某一天，也可以是类似 <code>&quot;2 years 1 day 3 minutes ago&quot;</code> 的相对日期。</p>
<p>我们其实还可以过滤出匹配指定条件的提交。例如 用 <code>--author</code> 选项显示指定作者的提交，用 <code>--grep</code> 选项搜索提交说明中的关键字。我们可以指定多个 <code>--author</code> 和 <code>--grep</code> 搜索条件，这样会只输出匹配 <strong>任意</strong> <code>--author</code> 模式和 <strong>任意</strong> <code>--grep</code> 模式的提交。然而，如果我们添加了 <code>--all-match</code> 选项， 则只会输出匹配 <strong>所有</strong> <code>--grep</code> 模式的提交。</p>
<p>还有一个非常有用的过滤器是 <code>-S</code>（俗称“pickaxe”选项，取“用鹤嘴锄在土里捡石头”之意）， 它接受一个字符串参数，并且只会显示那些添加或删除了该字符串的提交。 假设我们想找出添加或删除了对某一个特定函数的引用的提交，可以调用：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log -S function_name</span><br></pre></td></tr></table></figure>

<h2 id="2-常用的限制选项"><a href="#2-常用的限制选项" class="headerlink" title="2. 常用的限制选项"></a><font size=3>2. 常用的限制选项</font></h2><table>
<thead>
<tr>
<th align="left">选项</th>
<th align="left">说明</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>-&lt;n&gt;</code></td>
<td align="left">仅显示最近的 n 条提交。</td>
</tr>
<tr>
<td align="left"><code>--since</code>, <code>--after</code></td>
<td align="left">仅显示指定时间之后的提交。</td>
</tr>
<tr>
<td align="left"><code>--until</code>, <code>--before</code></td>
<td align="left">仅显示指定时间之前的提交。</td>
</tr>
<tr>
<td align="left"><code>--author</code></td>
<td align="left">仅显示作者匹配指定字符串的提交。</td>
</tr>
<tr>
<td align="left"><code>--committer</code></td>
<td align="left">仅显示提交者匹配指定字符串的提交。</td>
</tr>
<tr>
<td align="left"><code>--grep</code></td>
<td align="left">仅显示提交说明中包含指定字符串的提交。</td>
</tr>
<tr>
<td align="left"><code>-S</code></td>
<td align="left">仅显示添加或删除内容匹配指定字符串的提交。</td>
</tr>
</tbody></table>
<h2 id="3-使用实例-1"><a href="#3-使用实例-1" class="headerlink" title="3. 使用实例"></a><font size=3>3. 使用实例</font></h2><p>如果要在 Git 源码库中查看 Junio Hamano 在 2008 年 10 月其间， 除了合并提交之外的哪一个提交修改了测试文件，可以使用下面的命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git <span class="built_in">log</span> --pretty=<span class="string">&quot;%h - %s&quot;</span> --author=<span class="string">&#x27;Junio C Hamano&#x27;</span> --since=<span class="string">&quot;2008-10-01&quot;</span> --before=<span class="string">&quot;2008-11-01&quot;</span> --no-merges -- t/</span></span><br><span class="line">5610e3b - Fix testcase failure when extended attributes are in use</span><br><span class="line">acd3b9e - Enhance hold_lock_file_for_&#123;update,append&#125;() API</span><br><span class="line">f563754 - demonstrate breakage of detached checkout with symbolic link HEAD</span><br><span class="line">d1a43f2 - reset --hard/read-tree --reset -u: remove unmerged new paths</span><br><span class="line">51a94af - Fix &quot;checkout --track -b newbranch&quot; on detached HEAD</span><br><span class="line">b0ad11e - pull: allow &quot;git pull origin $something:$current_branch&quot; into an unborn branch</span><br></pre></td></tr></table></figure>

<p>在近 40000 条提交中，上面的输出仅列出了符合条件的 6 条记录。</p>
<h1 id="八、自定义提交历史记录"><a href="#八、自定义提交历史记录" class="headerlink" title="八、自定义提交历史记录"></a><font size=3>八、自定义提交历史记录</font></h1><h2 id="1-定制-git-log"><a href="#1-定制-git-log" class="headerlink" title="1. 定制 git log "></a><font size=3>1. 定制 git log </font></h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">个人定制版 git <span class="built_in">log</span></span></span><br><span class="line">git log --graph --pretty=format:&#x27;%C(magenta)[%an]%C(reset) %C(red)%h%C(reset) : %C(green)%s%C(reset) %C(yellow)%d%C(reset) %C(blue)(%cr)%C(reset) &#x27; --abbrev-commit --date=relative # 相对时间</span><br><span class="line"></span><br><span class="line">git log --graph --pretty=format:&#x27;%C(magenta)[%an]%C(reset) %C(red)%h%C(reset) : %C(green)%s%C(reset) %C(yellow)%d%C(reset) %C(blue)(%cd)%C(reset) &#x27; --abbrev-commit --date=format:&#x27;%Y-%m-%d %H:%M:%S&#x27; # 绝对时间</span><br></pre></td></tr></table></figure>

<p><strong>【说明】</strong>一般来说 format 后边跟的是双引号 <code>&quot;</code> ，但是若想使用 alias 创建自定义命令的话，需要改为**单引号 <code>&#39;</code> **，否则会报错。</p>
<h2 id="2-自定义一个git-log命令"><a href="#2-自定义一个git-log命令" class="headerlink" title="2. 自定义一个git log命令"></a><font size=3>2. 自定义一个git log命令</font></h2><p>上边的输入不免有些麻烦，每次都要输入这个么一长串命令嘛？Git其实是支持我们自定义命令的。</p>
<h3 id="2-1-自定义方法一：修改-gitconfig-文件"><a href="#2-1-自定义方法一：修改-gitconfig-文件" class="headerlink" title="2.1 自定义方法一：修改 ~&#x2F;.gitconfig 文件"></a><font size=3>2.1 自定义方法一：修改 ~&#x2F;.gitconfig 文件</font></h3><p>linux中这个文件就在<code>~/.gitconfig</code>，在windows中，文件位于<code>&quot;C:\Users\&lt;用户名&gt;\.gitconfig&quot;</code>。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim ~/.gitconfig</span><br></pre></td></tr></table></figure>

<p>打开后在结尾处添加以下内容：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[alias]</span><br><span class="line">    mylog = log --graph --pretty=format:&#x27;%C(magenta)[%an]%C(reset) %C(red)%h%C(reset) : %C(green)%s%C(reset) %C(yellow)%d%C(reset) %C(blue)(%cd)%C(reset) &#x27; --abbrev-commit --date=format:&#x27;%Y-%m-%d %H:%M:%S&#x27;</span><br></pre></td></tr></table></figure>

<h3 id="2-2-自定义方法二：命令行输入"><a href="#2-2-自定义方法二：命令行输入" class="headerlink" title="2.2 自定义方法二：命令行输入"></a><font size=3>2.2 自定义方法二：命令行输入</font></h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git config --global alias.mylog &quot;log --graph --pretty=format:&#x27;%C(magenta)[%an]%C(reset) %C(red)%h%C(reset) : %C(green)%s%C(reset) %C(yellow)%d%C(reset) %C(blue)(%cd)%C(reset) &#x27; --abbrev-commit --date=format:&#x27;%Y-%m-%d %H:%M:%S&#x27;&quot;</span><br></pre></td></tr></table></figure>

<p>其实这个样子配置的话，最后也是修改的家目录下的.gitconfig文件。</p>
<h2 id="3-运行自定义命令"><a href="#3-运行自定义命令" class="headerlink" title="3. 运行自定义命令"></a><font size=3>3. 运行自定义命令</font></h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git mylog</span><br></pre></td></tr></table></figure>

<h2 id="4-实现效果"><a href="#4-实现效果" class="headerlink" title="4. 实现效果"></a><font size=3>4. 实现效果</font></h2><p>最终实现的效果如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/02%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/03%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/LV01-Git-04-Git%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93-03-%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2/img/image-20230622181340614.png" alt="image-20230622181340614" style="zoom:67%;" />
    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/f7668e71.html">LV01-Git-04-Git本地仓库-03-提交历史</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年07月02日 - 15:14</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/f7668e71.html" title="LV01-Git-04-Git本地仓库-03-提交历史">https://sumumm.github.io/post/f7668e71.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/Git/" rel="tag"><i class="fa fa-tag"></i> Git</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/b3401885.html" rel="prev" title="LV01-Git-04-Git本地仓库-04-撤销与版本回退">
                  <i class="fa fa-angle-left"></i> LV01-Git-04-Git本地仓库-04-撤销与版本回退
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/e3afad51.html" rel="next" title="LV01-Git-04-Git本地仓库-02-忽略文件">
                  LV01-Git-04-Git本地仓库-02-忽略文件 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">false</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
